﻿Type=Activity
Version=6
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Private cb As Object
	Private lvcitys As ListView
	Dim city As CityShen
	Private lblLocating As Label
	Private aloc As AMapLocationClient,aloc_option As locationOption
	Private pb As ProgressBar
	Private btnleft As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim telaw As telanywhere
telaw.Initialize(Activity)

	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("layselectcity")
	cb=Null
	initviews
End Sub
Sub initviews
	city=comm.getCurShen
	comm.setFA(btnleft,"fa-angle-left","")
	lvcitys.SingleLineLayout.Label.TextColor=Colors.Black
	Dim ts As CityShi
	For i=0 To city.lst.Size-1
		ts=city.lst.Get(i)
		lvcitys.AddSingleLine2("   "&ts.name,ts.name)
	Next
	comm.aio(Activity)
	initloc
	aloc.StartLocation
End Sub
Public Sub reqloc(cb_tmp As Object)
	cb=cb_tmp
	
End Sub
Sub initloc
	aloc.Init("aloc")
	aloc_option.init
	aloc_option.Interval=3000
	aloc_option.GPSFirst=False
	aloc_option.MockEnable=True
	aloc_option.LocationMode=aloc_option.Battery_Saving
	aloc_option.OnceLocation=True
	aloc.LocationOption=aloc_option
	
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
	If UserClosed Then
		aloc.StopLocation
		aloc.OnDestory
	End If
End Sub
Sub aloc_onLocationChanged(loc As AMapLocation)
	'Dim str As String="addr:"&loc.Address&" City:"&loc.City&" Road:"&loc.Road&" Country:"&loc.Country&" District:"&loc.District&" Latitude:"&loc.Latitude&" Longitude:"&loc.Longitude&" LocationDetail:"&loc.LocationDetail _
	'&" PoiName:"&loc.PoiName&" Province:"&loc.Province&" Street:"&loc.Street&CRLF&CRLF&"Str:"&loc.toStr
	Log(loc.toStr)
	'out puts:
	'{"country":"中国","province":"新疆维吾尔自治区","city":"乌鲁木齐市","cityCode":"0991","district":"新市区","adCode":"650104","address":"新疆维吾尔自治区乌鲁木齐市新市区鲤鱼山路靠近领世广场","road":"鲤鱼山路","street":"鲤鱼山路","number":"298号","poiName":"领世广场","errorCode":0,"errorInfo":"success","locationDetail":"-5","altitude":0,"bearing":0,"speed":0,"satellites":0,"aoiName":"","desc":"新疆维吾尔自治区 乌鲁木齐市 新市区 鲤鱼山路 靠近领世广场","time":1458556366701,"locationType":2,"accuracy":91,"latitude":43.884021,"longitude":87.598392,"provider":"lbs"}
	If loc.ErrorCode<>0 Then 
		lblLocating.Text="定位失败"
		ToastMessageShow("errCode:"&loc.ErrorCode&CRLF&loc.ErrorInfo,True)
	Else
		If loc.City.EndsWith("市") Then 
			lblLocating.Text="当前定位:"&loc.City.Trim.SubString2(0,loc.City.Length-1)
		Else
			lblLocating.Text="当前定位:"&loc.City.Trim
		End If
	End If
	
	pb.Visible=False
	aloc.StopLocation
End Sub

Sub lvcitys_ItemClick (Position As Int, Value As Object)
	g_store.conf.Put("curcity",Value)
	CallSubDelayed(cb,"citySelected")
	Activity.Finish
End Sub

Sub ivback_Click
	Activity.Finish
End Sub

Sub lblLocating_Click
	'如果没有定位成功就不响应点击事件
	If lblLocating.Text.Contains("正在定位") Then Return 
	g_store.conf.Put("curcity",lblLocating.Text.Trim)
	aloc.StopLocation
	CallSubDelayed(cb,"citySelected")
	Activity.Finish
End Sub

Sub lblrefush_Click
	pb.Visible=True
	DoEvents
	lblLocating.Text="正在定位..."
	aloc.StartLocation
End Sub